<template>
    <view class="returnOrderList">

        <scroll-view scroll-y="true" class="swiper-item-box" bindscrolltolower="onReachBottom">
            <repeat for="{{list}}" key="index" index="index" item="item">
                <view class="returnOrderList_list" data-index="{{index}}" data-state="{{item.state}}" @tap="gotoDetail">
                    <view class="header">
                        <text>退货</text>
                    </view>
                    <view class="content">
                        <view class='returnOrderList_img'>
                            <image src="{{item.topicImage}}"></image>
                        </view>
                        <view class='returnOrderList_txt'>
                            <view class="txt_1">{{item.goodsName}}</view>
                            <view class="txt_2">
                                <text>{{item.goodsSize}}码</text>
                            </view>
                        </view>
                    </view>
                </view>
            </repeat>
            <!--加载更多时动画-->
            <bottomLoadMore :show.sync="showLoading" message="正在加载"></bottomLoadMore>
            <!--暂无数据显示-->
            <placeholder wx:if="{{is_empty}}" message="暂无退货"></placeholder>
        </scroll-view>

    </view>
</template>
<script>
    import wepy from 'wepy';
    import api from '@/api/api';
    import BottomLoadMore from "../../components/common/bottomLoadMore"
    import Placeholder from "../../components/common/placeholder"
    import {
        USER_INFO, USER_SPECICAL_INFO, SYSTEM_INFO, ORDERDETAIL
    } from '@/utils/constant';

    export default class returnOrderList extends wepy.page {
        config = {  // 配置当前页面
            navigationBarTitleText: '退货清单'    // 头部标题
        };
        components = {
            bottomLoadMore: BottomLoadMore,
            placeholder: Placeholder
        };

        data = {
            list: [],
            winHeight: 0,
            //当前页面
            currentPage: 1,
            //总页数
            page_total: 0,
            //是否显示 底部loading
            showLoading: true,
            //防止重复加载
            preventRepeatReuqest: false,
            is_empty: false,
            from:''
        };

        // 获取鉴定数据列表
        async getAllReturns(currentPage,size) {
            let self = this;
            let userID = wepy.getStorageSync('userId') || '';
            let token = wepy.getStorageSync("token");

            const json = await api.listOrderReturn({
                query:{
                    "params['userId']":userID,
                    "page":currentPage || 1,
                    "limit":size || 10,
                    "sortField":'goodsName',
                    "dir":'ASC'
                }
            });
            if (json.data.code == 0) {
                self.list = [...self.list, ...json.data.data.rows];
                self.page_total = Math.ceil(json.data.data.total / 10)
                if (json.data.page_total == 0) {
                    //暂无数据
                     self.is_empty = true;
                }
            }
            self.showLoading = false;
            self.$apply();
        }
        onShow(){
            let that = this;
            that.list = [];
            that.getAllReturns();
        }
        //加载更多
        onReachBottom() {
            let that = this;
            that.showLoading = true;
            //判断总页数是否大于翻页数
            if ((that.page_total) > that.currentPage) {
                //防止重复加载
                if (that.preventRepeatReuqest) {
                    return true;
                }
                that.preventRepeatReuqest = true;
                that.currentPage++;
                that.getAllReturns(that.currentPage);
                that.preventRepeatReuqest = false;
            } else {
                that.showLoading = false;
            }
        };

        methods = {  // 方法
            gotoDetail(e){
                const t = this;
                let i = +e.currentTarget.dataset.index;
                t.list[i]['fail'] = {
                    name:"退货",
                    state:+e.currentTarget.dataset.state,
                    way:"1"
                };
                wx.setStorageSync(ORDERDETAIL,t.list[i]);
                wx.navigateTo({
                    url: '/pages/order/ordDetails'
                })
            }
        }
        events = {};
    }

</script>
<style lang="less">
    .returnOrderList{
        overflow: hidden;
        .swiper-item-box{
            height: auto;

            .returnOrderList_list{
                width: 100%;
                background: #ffffff;
                margin-bottom: 30rpx;
                .header{
                    height: 80rpx;
                    line-height: 80rpx;
                    border-bottom: solid 1px #e6e6e6;
                    border-top: solid 1px #e6e6e6;
                    color: #ffb023;
                    width: 100%;
                    text-align: right;
                    text{
                        padding-right: 30rpx;
                    }
                }
                .content{
                    padding: 20rpx 0 20rpx 30rpx;
                    border-bottom: solid 1px #e6e6e6;
                    height: 210rpx;
                    .returnOrderList_img{
                        float: left;
                        width: 200rpx;
                        height: 200rpx;
                        border: solid 1px #e6e6e6;
                        image{
                            width: 100%;
                            height: 100%;
                        }
                    }
                    .returnOrderList_txt{
                        float: left;
                        padding-left: 20rpx;
                        .txt_1{
                            height: 150rpx;
                        }
                        .txt_2{
                            .num{
                                margin-left: 15rpx;
                            }
                        }
                    }
                }
            }
        }
    }
</style>
